While...Wend Statement
Repeatedly executes a series of statements while a specified condition is True.
Syntax
While condition
[Statements]
[ Continue]
[ Exit]
[Statements]
Wend
Part | Description |
While | Begins the loop. |
Condition | Any valid Boolean expression. When this expression evaluates to True, the loop will exit. |
Statements | Statements to be executed repeatedly (until condition evaluates to False). |
Continue | If a Continue statement is present, execution will skip over the remaining statements in the loop and resume with a new iteration of the loop. Optional arguments of the Continue statement allow you to specify which loop will iterate next, in cases of multiple nested loops. |
Exit | If an Exit statement is present, execution of the loop is terminated and resumes with the next line following the loop. |
Wend | Ends the loop. Condition is evaluated to determine if the loop should exit. |
Notes
If Condition is True, all statements are executed until the Wend statement is reached. If Condition is still True, the process is repeated. If Condition is False, then execution continues with the statement following the Wend statement.
While...Wend statements can be nested to any level. Each Wend statement goes with the previous While statement. It is permissible to place Dim statements inside loops, including While loops.
When a loop runs, it takes over the interface, preventing the user from interacting with menus and controls. If the loop is very lengthy, you can move the code for the loop to a separate Thread, allowing it to execute in the background.
Example
This example uses the While...Wend statement to increment a variable.
See Also
Continue, Do...Loop, Exit, For...Next statements; Application, Thread classes.